package LeetCode.Arrays;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : LdLtd
 * @Date : 2023/8/3
 * @Description:722. 删除注释
 */
public class remove_comments {
    public static void main(String[] args) {
        Solution solution = new Solution();
        String []source = {"/*Test program */", "int main()", "{ ", "  // variable declaration ", "int a, b, c;", "/* This is a test", "   multiline  ", "   comment for ", "   testing */", "a = b + c;", "}"};
        System.out.println(solution.removeComments(source).toString());
    }
    /*没考虑行内注释以及换行等等问题*/
    static class Solution {
        public List<String> removeComments(String[] source) {
            int flag=0;
            List<String> res = new ArrayList<>();
            for (String s : source) {
                if(s.trim().startsWith("//")||(flag==1)){
                    if(s.trim().endsWith("*/")){
                        flag=0;
                    }else if(s.trim().startsWith("//")) {
                        res.add(" ");
                    }
                    continue;
                }else if(s.trim().startsWith("/*")){
                    if(s.trim().endsWith("*/")){
                        continue;
                    }
                    flag=1;
                }else {
                    res.add(s);
                }
            }
            return res;
        }
    }
}
